package org.itsolutions.javaBackup.logger;

import org.slf4j.MDC;
/**
 * 
 * @author Stano Fujdiar
 */
public final class NDC {
	/**
	 * 
	 */
	public static final String PREFIX = "NDC";
	
	/**
	 * 
	 */
	private NDC() {
	}

	/**
	 * 
	 * @return
	 */
	private static int size() {
		int i = 0;
		while (true) {
			String val = MDC.get(PREFIX + i);
			if (val != null) {
				i++;
			} else {
				break;
			}
		}
		return i;
	}

	/**
	 * 
	 * @param pVal val
	 */
	public static void push(String pVal) {
		int next = size();
		MDC.put(PREFIX + next, pVal);
	}

	/**
	 * 
	 * @return val
	 */
	public static String pop() {
		int next = size();
		if (next == 0) {
			return "";
		}
		int last = next - 1;
		String key = PREFIX + last;
		String val = MDC.get(key);
		MDC.remove(key);
		return val;
	}

	/**
	 * 
	 * @return val
	 */
	public static String peek() {
		int next = size();
		if (next == 0) {
			return "";
		}
		int last = next - 1;
		String key = PREFIX + last;
		String val = MDC.get(key);
		return val;
	}
}